<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css"/>
	<style>
        html, body {
            background-color: #f8f8f8;
        }
        .order_complete {
            background-color: #fff;
            text-align: center;
            padding: 15px 0;
            margin-bottom: 6px;
            display: none;
        }
        .order_complete img {
            height: 36px;
            vertical-align: middle;
        }
        .order_complete .order_p {
            font-size: 15px;
            font-weight: bold;
            color: #333;
            margin-top: 11px;
        }
        .order_complete .order_btn {
            margin-top: 20px;
            overflow: hidden;
            display: inline-block;
        }
        .order_complete .order_btn .btn {
            width: 70px;
            height: 26px;
            line-height: 26px;
            float: left;
            color: #e62442;
            border: 1px solid #e62442;
            border-radius: 5px;
            margin-right: 10px;
            font-size: 12px;
        }
        .order_complete .order_btn .btn:last-child {
            margin-right: 0;
        }
        .order_complete .order_btn .btn_s {
            color: #fff;
            background-color: #e62442;
        }
         .order_unpay {
            background-color: #fff;
            text-align: center;
            padding: 15px 0;
            margin-bottom: 6px;
            display: none;
        }
        .order_unpay img {
            height: 36px;
            vertical-align: middle;
        }
        .order_unpay .order_p {
            font-size: 15px;
            font-weight: bold;
            color: #333;
            margin-top: 11px;
        }
        .order_canceled {
            background-color: #fff;
            text-align: center;
            padding: 15px 0;
            margin-bottom: 6px;
            display: none;
        }
        .order_canceled img {
            height: 36px;
            vertical-align: middle;
        }
        .order_canceled .order_p {
            font-size: 15px;
            font-weight: bold;
            color: #333;
            margin-top: 11px;
            margin-bottom: 15px;
        }
        .order_canceled .order_text {
            width: 200px;
            margin: auto;
            font-size: 13px;
            color: #999;
            text-align: center;
        }
        .order_prompt {
            background-color: #fff;
            text-align: center;
            padding: 15px 0;
            margin-bottom: 6px;
            display: none;
        }
        .order_prompt img {
            height: 36px;
            vertical-align: middle;
        }
        .order_prompt .order_p {
            font-size: 15px;
            font-weight: bold;
            color: #333;
            margin-top: 11px;
            margin-bottom: 15px;
        }
        .order_prompt .order_text {
            width: 210px;
            margin: auto;
            font-size: 13px;
            color: #999;
            text-align: center;
        }
        .seller_info {
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;
            padding: 10px 15px;
            border-bottom: 1px solid #e8e8e8;
        }
        .seller_info .seller_info_l .seller_img {
            width: 45px;
            height: 45px;
        }
        .seller_info .seller_info_l .seller_img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .seller_info .seller_info_c {
            width: 0;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            padding: 0 10px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .seller_info .seller_info_r img {
            height: 13px;
            display: block;
        }
        .order_info {
            background-color: #fff;
            margin-bottom: 6px;
        }
        .order_info .goods {
            padding: 16px 15px;
            border-bottom: 1px solid #e8e8e8;
            display: -webkit-box;
            display: -webkit-flex;
            color: #999;
        }
        .order_info .goods .goods_l {
            width: 0;
            box-flex:1;
            -webkit-box-flex:1; 
            flex:1;
            -webkit-flex:1; 
        }
        .order_info .goods ul li {
            margin-bottom: 19px;
        }
        .order_info .goods ul li:last-child .li_box {
            margin-bottom: 0;
        }
        .order_info .goods .li_boxl {
            font-size: 14px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            padding-right: 5px;
        }
        .order_info .goods .li_boxr {
            font-size: 12px;
            overflow: hidden;
        }
        .order_info .goods .li_boxr .goods_num {
            margin-right: 17px;
            float: left;
        }
        .order_info .goods .li_boxr .goods_price {
            float: right;
        }
        .discount_box {
            border-bottom: 1px solid #e8e8e8;
        }
        .discount {
            height: 50px;
            line-height: 50px;
            padding: 0 15px;
            display: -webkit-box;
            display: -webkit-flex;
        }
        .discount .discount_l {
            font-size: 12px;
            color: #999;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
        }
        .discount .discount_l span {
            width: 16px;
            height: 16px;
            line-height: 16px;
            text-align: center;
            background-color: #ff5f78;
            color: #fff;
            display: inline-block;
            border-radius: 3px;
            margin-right: 5px;
        }
        .discount .discount_r {
            color: #999;
            font-size: 12px;
        }
        .distribution_price {
            height: 50px;
            line-height: 50px;
            padding: 0 15px;
            display: -webkit-box;
            display: -webkit-flex;
            border-bottom: 1px solid #e8e8e8;
        }
        .distribution_price .distribution_price_l {
            color: #333;
            font-size: 15px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
        }
        .distribution_price .distribution_price_r {
            color: #999;
            font-size: 12px;
        }
        .common_box {
            height: 50px;
            line-height: 50px;
            padding: 0 15px;
            display: -webkit-box;
            display: -webkit-flex;
            border-bottom: 1px solid #e8e8e8;
            background-color: #fff;
        }
        .common_box .common_boxl {
            color: #333;
            font-size: 15px;
            padding-right: 5px;
        }
        .common_box .common_boxr {
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            color: #999;
            font-size: 12px;
            text-align: right;
        }
        .common_box .gst_num {
            color: #999;
        }
        .no_border_bottom {
            border-bottom: none;
        }
        .price_num {
            color: #e62442;
            font-size: 15px;
        }
        .title_p {
            height: 35px;
            line-height: 41px;
            padding: 0 15px;
            font-size: 12px;
            color: #999;
        }
        .distribution_box {
            padding: 14px 15px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            border-bottom: 1px solid #e8e8e8;
            background-color: #fff;
        }
        .distribution_box .distribution_boxl {
            color: #333;
            font-size: 15px;
            padding-right: 5px;
        }
        .distribution_box .distribution_boxr {
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            color: #999;
            font-size: 12px;
            text-align: right;
        }
        .distribution_box .distribution_boxr .distribution_p1 {
            margin-bottom: 10px;
        }
        .staff_box {
            padding: 14px 15px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;

        }
        .staff_box .staff_boxl {
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            color: #333;
            font-size: 15px;
            padding-right: 5px;
        }
        .staff_box .staff_boxc {
            margin-right: 7px;
        }
        .staff_box .staff_boxc .staff_img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            overflow: hidden;
            border: 1px solid #d3d3d3;
        }
        .staff_box .staff_boxc .staff_img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .staff_box .staff_boxr {
            color: #999;
            font-size: 12px;
        }
        .staff_box .staff_boxr .staff_p1 {
            margin-bottom: 10px;
        }
        .order_unpay {
            display: none;
        }
        .gst_box {
            display: none;
        }
        .hidden{
            display: none !important;
        }
        .h10 {
            height: 10px;
        }
        .staff_phone {
            height: 65px;
            background-color: #fff;
            border-bottom: 1px solid #e8e8e8;
            overflow: hidden;
        }
        .staff_phone .staff_phonel {
            height: 65px;
            float: left;
            display: -webkit-box;
            -webkit-box-align: center;
            padding: 0 15px;
        }
        .staff_phone .staff_phonel .img_box {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            overflow: hidden;
            border: 1px solid #d3d3d3;
        }
        .staff_phone .staff_phonel .img_box img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .staff_phone .staff_phoner {
            height: 65px;
            float: right;
            padding: 0 15px;
            display: -webkit-box;
            -webkit-box-align: center;
        }
        .staff_phone .staff_phoner img {
            width: 36px;
            display: block;
        }
        .cancel_desc {
            display: none;
        }
		.mb10 {
			margin-bottom: 10px;
		}
        .remark_box {
            background-color: #fff;
        }
        .remark_box .remark_detail {
            width: 100%;
            /*height: 60px;*/
            color: #333;
            font-size: 14px;
            padding: 10px 15px;
            box-sizing: border-box;
            display: block;
        }
        .remark_box .remark_detail .remark_desc{
            color: #999;
        }
	</style>
</head>
<body>
	<div class="order_complete">
		<img src="../image/order_complete.png">
		<div class="order_p">订单已完成</div>
		<div class="order_btn hidden">
			<div class="btn btn_s" tapmode onclick="fnEvaluate();">查看评价</div>
		</div>
	</div>
	<div class="order_canceled">
		<img src="../image/order_canceled.png">
		<div class="order_p">已取消订单</div>
		<div class="order_text">该订单金额将于3至5个工作日内返回用户使用的账户。</div>
	</div>
    <div class="order_info">
        <div class="goods" id="goods_ul">
<!--             <div class="goods_l">
                <ul>
                    <li>
                        <div class="li_boxl">菜品名称</div>
                    </li>
                    <li>
                        <div class="li_boxl">餐盒</div>
                    </li>
                </ul>
            </div>
            <div class="goods_r">
                <ul>
                    <li>
                        <div class="li_boxr">
                            <span class="goods_num">×1</span>
                            <span class="goods_price">RM19</span>
                        </div>
                    </li>
                    <li>
                        <div class="li_boxr">
                            <span class="goods_num">×33</span>
                            <span class="goods_price">RM3</span>
                        </div>
                    </li>
                </ul>
            </div> -->
        </div>
        <div class="discount_box">
            <ul>
                <li>
                    <div class="discount">
                        <div class="discount_l"><span>减</span><time class="coupon_str">满减</time></div>
                        <div class="discount_r">-RM<span class="coupon">0.00</span></div>
                    </div>
                </li>
                <li>
                    <div class="discount">
                        <div class="discount_l"><span >卷</span>使用优惠卷</div>
                        <div class="discount_r">-RM<span class="ticket">0.00</span></div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="common_box">
            <div class="common_boxl">配送费</div>
            <div class="common_boxr">RM<span class="delivery_price"></span></div>
        </div>
        <div class="common_box gst_box">
            <div class="common_boxl">GST<span class="gst_num">（6.00%）</span></div>
            <div class="common_boxr">RM<span class="gst_fee"></span></div>
        </div>
        <div class="common_box no_border_bottom">
            <div class="common_boxl">订单金额</div>
            <div class="common_boxr price_num">RM<span class="must_pay"></span></div>
        </div>
    </div>
<!--     <div class="remark_box">
        <textarea placeholder="请输入文字"></textarea>
    </div> -->
    <div class="remark_box">
        <div class="remark_detail"><span class="remark_desc"></span></div>
    </div>
    <div class="title_p">配送信息</div>
    <div class="distribution_box">
        <div class="distribution_boxl">收货地址</div>
        <div class="distribution_boxr">
            <div class="distribution_p1 address_detail"></div>
            <div class="distribution_p2"><span class="username"></span> <span class="tel"></span></div>
        </div>
    </div>
    <div class="staff_box hidden">
        <div class="staff_boxl">骑手信息</div>
        <div class="staff_boxc">
            <div class="staff_img">
                <img src="../image/temp/1.png">
            </div>
        </div>
        <div class="staff_boxr">
            <div class="staff_p1 staff_name"></div>
            <div class="staff_p2 staff_phone"></div>
        </div>
    </div>
    <div class="title_p">订单信息</div>
    <div class="common_box">
        <div class="common_boxl">订单号</div>
        <div class="common_boxr order_number"></div>
    </div>
    <div class="common_box">
        <div class="common_boxl">支付方式</div>
        <div class="common_boxr">在线支付</div>
    </div>
    <div class="common_box no_border_bottom">
        <div class="common_boxl">下单时间</div>
        <div class="common_boxr create_time"></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="goodsTpl" type="text/x-dot-template">
    <div class="goods_l">
        <ul >
            {{ for(var i=0;i<it['goods'].length;i++){ }}
                <li>
                    <div class="li_boxl">{{=it['goods'][i]['goods_name']}}</div>
                </li>
            {{ }; }}
            <li>
                <div class="li_boxl">餐盒</div>
            </li>
        </ul>
    </div>
    <div class="goods_r">
        <ul>
            {{ for(var i=0;i<it['goods'].length;i++){ }}
                <li>
                    <div class="li_boxr">
                        <span class="goods_num">×{{=it['goods'][i]['goods_num']}}</span>
                        <span class="goods_price">RM{{=(it['goods'][i]['price']*it['goods'][i]['goods_num']).toFixed(2)}}</span>
                    </div>
                </li>
            {{ }; }}
            <li>
                <div class="li_boxr">
                    <span class="goods_num">×{{=it['canteen_num']}}</span>
                    <span class="goods_price">RM{{=(it['canteen_price']*1).toFixed(2)}}</span>
                </div>
            </li>
        </ul>
    </div>
</script>
<script type="text/javascript">
	apiready = function(){
		openLoading();
        id = api.pageParam.id;
        status = api.pageParam.status;
        user = $api.getStorage('shop_data');
        if(status == 5 || status == 6 ) {
        	$('.order_complete').show();
        	if(status == 6) {
        		$('.order_btn').removeClass('hidden');
        	}
        }else if(status == 'refund') {
        	$('.order_canceled').show();
        }
        getOrder();
		api.addEventListener({
		    name: 'cancelOrderEvent'
		}, function(ret, err) {
		    if (ret) {
		        api.confirm({
		            title: '提示',
		            msg: '确认要取消订单吗',
		            buttons: ['确定', '取消']
		        }, function(ret, err){
		            if( ret ){
		                 if(ret.buttonIndex == 1) {
		                 	fnCancelOrder();
		                 }
		            }
		        });
		    }
		});

		//确认订单
		api.addEventListener({
		    name: 'confirmOrderEvent'
		}, function(ret, err) {
		    if (ret) {
		        fnConfirmOrder();
		    }
		});
	};
	
	//查看评价
	function fnEvaluate() {
		api.openWin({
			name: 'evaluate_order.html',
			url: './evaluate_order.html',
            pageParam : {
                order_id : id
            }
		});
	}

	 function getOrder() {
        user = $api.getStorage('shop_data');
        api.ajax({
            url: rootPath+'/api/seller_order/order_detail',
            method: 'get',
            data: {
                values: { 
                    order_id: id,
                    shop_id:user.id,
                    token:user.token
                },

            }
        }, function(ret, err) {
            if (ret) {
                shop_id = ret.data.shop_id;
                setDotData(ret.data,'goodsTpl','goods_ul',true);
                $('.shop_title').text(ret.data.shop_name);
                var shop_img = formatVideoImg(ret.data.shop_img);
                $('.shop_img').attr('src',shop_img);
                if(ret.data.gst_fee > 0) {
                  $('.gst_box').css('display','-webkit-flex');
                  $('.gst_fee').text(parseFloat(ret.data.gst_fee).toFixed(2));
                }else{
                    $('.gst_box').css('display','-webkit-flex');
                    $('.gst_fee').text('0.00');
                }
                $('.delivery_price').text(ret.data.delivery_price);
                $('.must_pay').text(ret.data.must_pay);
                $('.address_detail').text(ret.data.address_detail);
                $('.username').text(ret.data.username);
                $('.tel').text(ret.data.tel);
                $('.order_number').text(ret.data.order_number);
                $('.create_time').text(ret.data.create_time);
                if(ret.data.coupon) {
                	$('.coupon_str').text(ret.data.coupon_str);
                	$('.coupon').text(parseFloat(ret.data.coupon.reduce_price).toFixed(2));
                }else{
                    $('.coupon').text('0.00');
                }
                if(ret.data.ticket){
                	$('.ticket').text(parseFloat(ret.data.ticket.price).toFixed(2));
                }else{
                    $('.ticket').text('0.00');
                }
                var _remark = ret.data.remark?ret.data.remark:'暂无备注';
                $(".remark_desc").text(_remark);
            } else {
                alert(JSON.stringify(err.msg));
            }
            closeLoading();
        });
    }

    function fnCancelOrder() {
    	api.ajax({
    	    url: rootPath+'/api/seller_order/cancel_shop_order',
    	    method: 'post',
    	    data: {
    	        values: { 
    	            shop_id: user.id,
    	            token : user.token,
    	            order_id : id
    	        },

    	    }
    	}, function(ret, err) {
    	    if (ret) {
    	        if(ret.status == 200) {
    	        	api.toast({
    	        	    msg: '取消成功，款项原路返回',
    	        	    location : 'middle'
    	        	});
    	        	api.sendEvent({
    	        	    name: 'orderChangeEvent',
    	        	    extra: {
    	        	    }
    	        	});
    	        	setTimeout(function(){
    	        		api.closeWin();
    	        	},1000);
    	        }else {
    	        	api.toast({
    	        	    msg: ret.msg,
    	        	    location: 'middle'
    	        	});
    	        }
    	    } else {
    	        alert(JSON.stringify(err.msg));
    	    }
    	});
    }

    function fnConfirmOrder() {
    	api.ajax({
    	    url: rootPath+'/api/seller_order/confirm_shop_order',
    	    method: 'post',
    	    data: {
    	        values: { 
    	            shop_id: user.id,
    	            token : user.token,
    	            order_id : id
    	        },

    	    }
    	}, function(ret, err) {
    	    if (ret) {
    	        if(ret.status == 200) {
    	        	api.toast({
    	        	    msg: '确认成功',
    	        	    location : 'middle'
    	        	});
    	        	api.sendEvent({
    	        	    name: 'orderChangeEvent',
    	        	    extra: {
    	        	    }
    	        	});
    	        	setTimeout(function(){
    	        		api.closeWin();
    	        	},1000);
    	        }else {
    	        	api.toast({
    	        	    msg: ret.msg,
    	        	    location: 'middle'
    	        	});
    	        }
    	    } else {
    	        alert(JSON.stringify(err.msg));
    	    }
    	});
    }
</script>
</html>